'use strict';
module.exports = {
    /**
     * 检查已付款未设置展位状态订单
     * @url client/timedTask/pub/test 前端调用的url参数地址
     * data 请求参数
     * @param {String} params1  参数1
     */
    main: async (event) => {
        let { data = {}, userInfo, util, filterResponse, originalParam } = event;
        let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
        let { uid } = data;
        let res = {
            code: 0,
            msg: ""
        };
        // 业务逻辑开始-----------------------------------------------------------


        let nopayOrders = await vk.baseDao.selects({
            dbName: "bidding-booths", // 主表名
            pageIndex: 1,
            getMain: true,
            pageSize: -1,
            whereJson: {
                status: 2,
				buy_user:null
            },
            foreignDB: [
                {
                    dbName: "bidding-order", // 副表名
                    localKey: "_id", // 主表外键字段名
                    foreignKey: "booth_id", // 副表外键字段名
                    as: "order",
                    whereJson: {
                        status: 2,
                    },

                    limit: 1, // 当limit = 1时，以对象形式返回，否则以数组形式返回
                }
            ],
			lastWhereJson:{
			    "order" : _.exists(true)
			  }

        });
         console.log(nopayOrders)

        if (vk.pubfn.isNotNull(nopayOrders)) {
            for (let index = 0; index < nopayOrders.length; index++) {

                await vk.baseDao.updateById({
                    dbName: "bidding-booths", // 表名
                    id: nopayOrders[index]._id,
                    dataJson: { // 需要修改的数据
                        status: 3,
                        buy_user: nopayOrders[index].order.userid
                    }
                });
            }

        }


        // 业务逻辑结束-----------------------------------------------------------
        return res;
    }
}
